﻿using System;
using System.Collections.Generic;
using System.Data;

namespace Marmat.Data
{
    public class Connection : BaseConnection
    {
        private BaseConnection m_Connection;

        public Connection(string ConnectionString, SourceType SourceType)
        {
            switch (SourceType)
            {
                case SourceType.Access:
                    this.m_Connection = new Access(ConnectionString);
                    break;
                case SourceType.SQLServer:
                    this.m_Connection = new SQLServer(ConnectionString);
                    break;
                default:

                    throw new Exception("尚未实现构造方法。");
            }
        }

        public void Close()
        {
            this.m_Connection.Close();
        }

        public string ConnectionString
        {
            get
            {
                return this.m_Connection.ConnectionString;
            }

            set
            {
                this.m_Connection.ConnectionString = value;
            }
        }

        public ConnectionVersionEnum ConnectionVersion
        {
            get
            {
                return this.m_Connection.ConnectionVersion;
                // Me.GetConnection(Of String)()
            }
        }


        public string Name
        {
            get
            {
                return this.m_Connection.Name;
            }

            set
            {
                this.m_Connection.Name = value;
            }
        }

        public void Open()
        {
            this.m_Connection.Open();
        }

        // Public Function Load(ByVal sqlstr As String, ByVal page As DataPageLoadArgs) As System.Data.DataTable

        // End Function
        // Public Class DataPageLoadArgs

        // End Class
        public SourceType SourceType
        {
            get
            {
                return this.m_Connection.SourceType;
            }
        }

        public ConnectionState State
        {
            get
            {
                return this.m_Connection.State;
            }
        }

        public List<string> GetProceduresNames()
        {
            return this.m_Connection.GetProceduresNames();
        }

        public List<string> GetTableNames()
        {
            return this.m_Connection.GetTableNames();
        }

        public List<string> GetViewNames()
        {
            return this.m_Connection.GetViewNames();
        }

        public DataTable GetColumns(string TableName)
        {
            return this.m_Connection.GetColumns(TableName);
        }

        public DateTime GetDate()
        {
            return this.m_Connection.GetDate();
        }

        public object ExecuteScalar(ConnectionExecuteOptions options)
        {
            return m_Connection.ExecuteScalar(options);
        }

        public int ExecuteNonQuery(ConnectionExecuteOptions options)
        {
            return m_Connection.ExecuteNonQuery(options);
        }

        public DataTable ExecuteReader(ConnectionExecuteOptions options)
        {
            return m_Connection.ExecuteReader(options);
        }
    }
}